package com.eelpo.cmmp.uac.pages.action;

import java.util.Arrays;
import java.util.List;

import com.eelpo.cmmp.core.wicket.panel.container.SearchPanel;
import com.eelpo.cmmp.uac.dao.vo.Action;
import com.eelpo.cmmp.uac.dao.vo.enumed.Status;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

/**
 * <pre>
 * 动作管理查询参数面板
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class ActionSearchPanel<T> extends SearchPanel {

	private static final long serialVersionUID = 4415966945225546598L;

	public ActionSearchPanel(String id, Action action) {
		super(id);

		add(renderFeedbackPanel("feedback"));

		renderActionNameTextField(action);
		renderActionCodeTextField(action);
		renderActionStatusDropDownChoice(action);
		renderAddButton();
	}

	public void renderActionNameTextField(Action action) {
		add(new TextField<String>("txtActionName", new PropertyModel<String>(action, "name")));
	}

	public void renderActionCodeTextField(Action action) {
		add(new TextField<String>("txtActionCode", new PropertyModel<String>(action, "code")));
	}

	public void renderActionStatusDropDownChoice(Action action) {
		List<Status> dataList = Arrays.asList(new Status[] { Status.ENABLED, Status.DISABLED, Status.ALL });
		IModel<Status> model = new PropertyModel<Status>(action, "status");
		IChoiceRenderer<Status> choiceRenderer = new ChoiceRenderer<Status>("label", "value");
		add(new DropDownChoice<Status>("selStatus", model, dataList, choiceRenderer));
	}

	private void renderAddButton() {
		Link<Void> addLink = new Link<Void>("btnAdd") {

			private static final long serialVersionUID = -2793217311048977169L;

			public void onClick() {
				setResponsePage(new AddOrEditAction());
			}
		};

		add(addLink);
	}
}
